package com.example.smartf;

import com.example.smartf.model.mongo.Group;
import com.example.smartf.model.mongo.User;
import com.example.smartf.repository.mongoDB.MongoUserUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class mongoDBtest {
    @Resource
    MongoUserUtil mongoUserUtil;
    @Resource
    MongoTemplate mongoTemplate;

    @Test
    public void mongotest() throws Exception{
//        User user = mongoUtil.findByUsername("zzl");
//        System.out.println(user.getUsername());
//        String k[] = {"344","fdjsafsad"};
//        User user = new User("ypq",k);
//        mongoUserUtil.addUser(user);
//
//        System.out.println(mongoTemplate.findAll(User.class,"User"));
//        Query query = new Query(Criteria.where("users").is("1033457564@qq.com"));
//        query.addCriteria(  Criteria.where("devices").is("6af6188e14aa")  );
//        List<Group> groups = mongoTemplate.find(query,Group.class,"Group");
//        for (Group group : groups){
//            System.out.println(group.toString());
//        }
        String devs[] = new String[0];
        User user = new User("test",devs);
        mongoTemplate.save(user,"User");

    }
}
